﻿using System;

namespace ProblemsSet
{
    public class Problem_44 : BaseProblem
    {
        public override object GetResult()
        {
            long curMax = 2;
            while (true)
            {
                for (var i = curMax-1; i>=1; i--)
                {
                    var a = MathLogic.GetPenta(curMax);
                    var b = MathLogic.GetPenta(i);
                    var q = a + b;
                    if (!MathLogic.IsPenta(q)) continue;
                    q = a - b;
                    if (!MathLogic.IsPenta(q)) continue;
                    return q;
                }
                curMax++;
            }
            return -1;
        }


        public override string Problem
        {
            get
            {
                return @"Pentagonal numbers are generated by the formula, Pn=n(3n1)/2. The first ten pentagonal numbers are:

1, 5, 12, 22, 35, 51, 70, 92, 117, 145, ...

It can be seen that P4 + P7 = 22 + 70 = 92 = P8. However, their difference, 70  22 = 48, is not pentagonal.

Find the pair of pentagonal numbers, Pj and Pk, for which their sum and difference is pentagonal and D = |Pk  Pj| is minimised; what is the value of D?";
            }
        }

        public override bool IsSolved
        {
            get
            {
                return true;
            }
        }

        public override object Answer
        {
            get
            {
                return 5482660;
            }
        }
    }
}
